{% extends 'dashboard/base.html' %}

{% block body %}
    {#<link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.css" rel="stylesheet">#}
    {#    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>#}
    <script type="text/javascript">

        $("#checkAll").change(function () {
            $("input:checkbox").prop('checked', $(this).prop("checked"));
        });
        $(document).ready(function () {
            $('.btn-danger').click(function () {
                if (confirm('Are you sure you want to delete this?')) {
                    var scan_id = ['a7af5b68-b661-45ad-90fd-ffa27526cdce'];
                    $.each($("input[name='del_scan_id']:checked"), function () {
                        scan_id.push($(this).val());
                    });

                    var json_scanid = scan_id.join(", ");
                    $.ajax({
                        type: 'POST',
                        <!--contentType: 'application/json; charset=utf-8',-->
                        url: '{% url 'dockle:del_dockle' %}',
                        data: {
                            scan_id: json_scanid,
                            csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]').val()
                        },
                        sucess: function () {

                        }
                    });
                    setTimeout(location.reload(), 6000);
                }
            });

        });


    </script>


    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-body">
                    <div class="float-right">
                       {% if user.is_superuser == True or user.role.id == 2 %}
                        <div class="btn-group" role="group" aria-label="Basic example">
                            <a href="{% url 'report_upload:upload' %}" class="btn btn-primary btn-mini"><i
                                    class="icon-upload-alt"></i> Upload </a>
                        </div>
                        <button type="button" class="btn btn-danger btn-mini" onclick="">Delete Selected
                        </button>
                        {% endif %}
                    </div>
                    <br>
                    <br>
                    <br>
                    <div class="d-md-flex align-items-center">
                        <h1 class="card-title">Dockle Scan List</h1>
                    </div>
                    <br>
                    <div class="row">
                        <div class="table-responsive">
                            <table id="data_table" class="table table-bordered data-table">
                                <thead>
                                <tr>
                                    <th><label class="customcheckbox m-b-20">
                                        <input type="checkbox" id="mainCheckbox">
                                        <span class="checkmark"></span>
                                    </label></th>
                                    <th>Project Name</th>
                                    <th>Status</th>
                                    <th>Date Time</th>
                                    <th>Total</th>
                                    <th>Failed</th>
                                    <th>Warning</th>
                                    <th>Info</th>
                                    <th>Duplicates</th>
                                   {% if user.is_superuser == True or user.role.id == 2 %}
                                    <th></th>
                                    {% endif %}
                                </tr>
                                </thead>
                                <tbody>{% for data in all_dockle_scan %}
                                    <tr data-target="#">
                                        <td>
                                            <form>
                                                <label class="customcheckbox">
                                                    <input type="checkbox" class="listCheckbox"
                                                           value="{{ data.scan_id }}"
                                                           name="del_scan_id"
                                                           onClick="reload">
                                                    <span class="checkmark"></span>
                                                </label>
                                            </form>
                                        </td>
                                        <td>
                                            <a href="{% url 'dockle:dockle_all_vuln' %}?scan_id={{ data.scan_id }}">{{ data.project_name }}</a>
                                        </td>
                                        <td width="20%">
                                            <div>
                                                <div class="d-flex no-block align-items-center">
                                                    <span>{{ data.scan_status }}{{ data.vul_status }}% Completed</span>
                                                </div>
                                                <div class="progress{% if data.scan_status != '100.0' %} active progress-striped{% endif %}">
                                                    <div class="progress-bar progress-bar-striped"
                                                         role="progressbar"
                                                         style="width:
                                                                 {{ data.scan_status }}{{ data.vul_status }}%"
                                                         aria-valuenow="10" aria-valuemin="0"
                                                         aria-valuemax="100"></div>
                                                </div>
                                            </div>
                                        </td>
                                        <td>{{ data.date_time }}</td>
                                        <td><span
                                                class="badge badge-pill badge-dark">{{ data.total_vuln }}</span>
                                        </td>
                                        <td><span
                                                class="badge badge-pill badge-danger">{{ data.dockle_fatal }}</span>
                                        </td>
                                        <td><span
                                                class="badge badge-pill badge-orange">{{ data.dockle_warn }}</span>
                                        </td>
                                        <td><span
                                                class="badge badge-pill badge-info">{{ data.dockle_info }}</span>
                                        </td>
                                        <td><span
                                                class="badge badge-pill badge-secondary">{{ data.total_dup }}</span>
                                        </td>
                                   {% if user.is_superuser == True or user.role.id == 2 %}
                                        <td>
                                            <form action="{% url 'dockle:del_dockle' %}" method="post"
                                                  class="forms-sample">
                                                {% csrf_token %}
                                                <input type="hidden" name="scan_id" value="{{ data.scan_id }}"/>
                                                <!--<input type="hidden" name="scan_url" value="{{data.scan_url}}"/>-->
                                                <button class="btn btn-danger btn-mini"><i
                                                        class="fas fa-trash"></i></button>
                                            </form>
                                        </td>
                                    {% endif %}
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
